import cgi
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from entities import *
from Entities import *

def Add(versionName):
    version = db.GqlQuery("SELECT * FROM Version WHERE VersionName =:1",versionName)
    if version.count() == 0:
        version = Version(VersionName = versionName)
        version.put()
        return 1
    else:
        return 0
        
def Delete(versionName):
    version = db.GqlQuery("SELECT * FROM Version WHERE VersionName =:1",versionName)
    if version.count() == 0:
        return 0
    else:
        Version.delete(version)
        return 1
        
def Get():
    version_list = []
    versions = db.GqlQuery("SELECT * FROM Version")
    for version in versions:
        version_dict = {}
        version_dict["VersionName"] = version.VersionName
        version_dict["VersionID"] = version.key().id()
        version_list.append(version_dict)
    tuple_version = tuple(version_list)
    return tuple_version